package com.yunc.modules.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunc.base.exception.NoShopException;
import com.yunc.modules.shop.entity.Shop;
import com.yunc.modules.shop.mapper.ShopMapper;
import com.yunc.modules.shop.service.IShopService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("shopService")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ShopServiceImpl extends ServiceImpl<ShopMapper, Shop> implements IShopService {

    private final ShopMapper shopMapper;

    @Override
    public Shop getByUserId(String userId) {
        QueryWrapper<Shop> qw = new QueryWrapper<>();
        qw.eq("user_id", userId);
        Shop shop = this.getOne(qw);
        if (shop == null) {
            throw new NoShopException("需要有店铺");
        }
        return shop;
    }
}
